import snakeCase from 'lodash/snakeCase';
import dayjs from 'dayjs';

const table = {
	data() {
		return {
			dayjs,
			tableAction: 0,
		};
	},
	methods: {
		handleSortChange(sort) {
			this.queryParams.sortStr = snakeCase(sort.prop);
			this.queryParams.sortDesc = sort.order;
			this.getList();
		},
		setActionWidth() {
			this.tableAction = 50;
			this.$nextTick(() => {
				const action = document.querySelectorAll('.table-action');
				const button = [];
				for (let i = 0; i < action.length; i++) {
					button.push(action[i].querySelectorAll('.el-button'));
				}

				const width = Array.from(Array(button.length).keys()).map(() => 0);
				for (let i = 0; i < button.length; i++) {
					for (let j = 0; j < button[i].length; j++) {
						width[i] += button[i][j].clientWidth || 0;
					}
				}
				this.tableAction = this.tableAction + Math.max.apply(null, width);
			});
		},
	},
};
export default table;
